/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaServer.java
 *
 * Created on 26/08/2011, 17:31:14
 */
package tsb.UI.Ventanas;

import tsb.dominio.interfaces.*;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import tsb.UI.Ventanas.VentanaDeError;
import tsb.dominio.enumeraciones.AsignacionIP;
import tsb.dominio.dispositivos.hostfinal.Server;

/**
 *
 * @author Fede
 */
public class VentanaServer extends javax.swing.JFrame {
    
     private Server server;
      private ArrayList<InterfaceDeConeccion> listaInterfaces;

    /** Creates new form VentanaServer */
    public VentanaServer(String nombreAMostrar) {
        initComponents();
        
        listaInterfaces = new ArrayList<InterfaceDeConeccion>();
        
        tsb.gestores.GestorDeServer gestorServer = new tsb.gestores.GestorDeServer();
        Server server=gestorServer.getServer("Server-1");
       
        this.setServer(server);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelServer = new tsb.UI.Paneles.PanelServer();
        panelBotones = new javax.swing.JPanel();
        btnCancelar1 = new javax.swing.JButton();
        btnAceptar1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Server");

        panelBotones.setBackground(new java.awt.Color(255, 255, 255));

        btnCancelar1.setText("Cancelar");
        btnCancelar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar1ActionPerformed(evt);
            }
        });

        btnAceptar1.setText("Aceptar");
        btnAceptar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptar1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelBotonesLayout = new javax.swing.GroupLayout(panelBotones);
        panelBotones.setLayout(panelBotonesLayout);
        panelBotonesLayout.setHorizontalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(253, Short.MAX_VALUE)
                .addComponent(btnAceptar1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancelar1)
                .addContainerGap())
        );
        panelBotonesLayout.setVerticalGroup(
            panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotonesLayout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(panelBotonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar1)
                    .addComponent(btnAceptar1))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelBotones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar1ActionPerformed
        this.panelServer.getInterfaz1();        // TODO add your handling code here:
}//GEN-LAST:event_btnCancelar1ActionPerformed

    private void btnAceptar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptar1ActionPerformed
        
        Server server= this.getServer();
        tsb.gestores.GestorDeServer gestorServer = new tsb.gestores.GestorDeServer();
        if(gestorServer.editarServer(server)) {
            System.out.println("se actualizo la pc");
        } else {
            System.out.println("No se actualizo");
        }
    }//GEN-LAST:event_btnAceptar1ActionPerformed

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar1;
    private javax.swing.JButton btnCancelar1;
    private javax.swing.JPanel panelBotones;
    private tsb.UI.Paneles.PanelServer panelServer;
    // End of variables declaration//GEN-END:variables

 public Server getServer()
    {
        this.server.setNombreAMostrar(this.panelServer.getNombreAMostrar());
        this.server.setEstado(this.panelServer.getEncendido());
        this.server.setGateway(this.panelServer.getServdorDNS());
        this.server.setGateway(this.panelServer.getGateway());
        
        this.listaInterfaces.add(this.panelServer.getInterfaz1());
        this.listaInterfaces.add(this.panelServer.getInterfaz2());
        
        this.server.setInterfaces(listaInterfaces);
        
        return server;
        
    }
 
  public void setServer(Server pc)
    {
        this.server=pc;
        this.panelServer.setNombreAMostrar(pc.getNombreAMostrar());
        this.panelServer.setEncendido(pc.getEstado());
        
        this.panelServer.setGateway(pc.getGateway());
    }

}


